package com.qwe.graduation.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.qwe.graduation.entity.VideoLeave;
import com.qwe.graduation.entity.vo.MessageLeaveVo;
import com.qwe.graduation.entity.vo.VideoLeaveVo;
import com.qwe.graduation.mapper.VideoLeaveMapper;
import com.qwe.graduation.service.IVideoLeaveService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 视频留言表 服务实现类
 * </p>
 *
 * @author 林卓锋
 * @since 2023-02-02
 */
@Service
public class VideoLeaveServiceImpl extends ServiceImpl<VideoLeaveMapper, VideoLeave> implements IVideoLeaveService {


    @Autowired
    VideoLeaveMapper videoLeaveMapper;

    /**
     *
     * @param name
     * @param headline
     * @param module
     * @return
     */
    @Override
    public List<VideoLeaveVo> findList(String name, String headline, String module) {
        List<VideoLeaveVo> list = videoLeaveMapper.findList();
        List<VideoLeaveVo> list2 = list.stream()
                .filter(message->  !StringUtils.isBlank(name)?message.getName().contains(name):true)
                .filter(message->  !StringUtils.isBlank(headline)?message.getHeadline().contains(headline):true)
                .filter(message->  !StringUtils.isBlank(module)?message.getModule().contains(module):true)
                .sorted((Comparator.comparing(VideoLeaveVo::getLeaveTime).reversed()))
                .collect(Collectors.toList());

        return list2;
    }
}
